package com.ys.controller;

import com.ys.mapper.MembertypMapper;
import com.ys.mapper.RelationshipMapper;
import com.ys.pojo.Menu;
import com.ys.service.MembertypeService;
import com.ys.service.MenuService;
import com.ys.vo.ResultVo;
import com.ys.vo.TreeVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class ShouQuanContorller {
    @Resource
    private MembertypeService membertypeService;
    @Resource
    private MenuService menuService;

    @RequestMapping("/shuxing")
    @ResponseBody
    public ResultVo shuxing(Integer id){
        ResultVo resultVo = new ResultVo();
        List<TreeVo> list = menuService.finByShouquan(id);
        resultVo.setObj(list);
        return resultVo;
    }

    @Resource
    private RelationshipMapper relationshipMapper;

    @RequestMapping(value = "/doShouQaun", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ResultVo doShouQaun(Integer id,Integer[] ids){
        ResultVo resultVo = new ResultVo();
        try {
                 relationshipMapper.del(id);
                for (int i = 0; i < ids.length; i++) {
                    int v = relationshipMapper.add(id,ids[i]);
                    System.out.println(v);
                }
        } catch (Exception e) {
            resultVo.setMsg("权限修改失败!");
        }
        resultVo.setMsg("权限修改成功!");
        return resultVo;
    }
}
